#!/bin/bash

BACKUP_DIR="/home/backup"  
DATE=$(date +"%Y-%m-%d")             
MYSQL_USER="root"
MYSQL_PASSWORD="root"               
MYSQL_HOST="localhost"

mkdir -p ${BACKUP_DIR}

mysqldump -u ${MYSQL_USER} -p${MYSQL_PASSWORD} -h ${MYSQL_HOST} --all-databases > ${BACKUP_DIR}/alldb_backup_${DATE}.sql

if [ $? -eq 0 ]; then
    echo "Backup successful: ${BACKUP_DIR}/alldb_backup_${DATE}.sql"
else
    echo "Backup failed"
    exit 1
fi

# scp ${BACKUP_DIR}/alldb_backup_${DATE}.sql user@ip:/home/backup/alldb_backup_${DATE}.sql